package com.xujl.mvcbind.window;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.xujl.mvcbind.R;

/**
 * 消息确认弹窗
 */
public class MessageConfirmWindow extends BaseWindow implements View.OnClickListener {
    private TextView mInfoTv;

    private Callback mCallback;

    public MessageConfirmWindow (Context context) {
        super(context);
        setPopupGravity(Gravity.CENTER);
        setOutSideDismiss(false);
    }

    @Override
    public View onCreateContentView () {
        final View view = createPopupById(R.layout.window_confirm);
        mInfoTv = view.findViewById(R.id.tv_info);
        view.findViewById(R.id.tv_confirm).setOnClickListener(this);
        view.findViewById(R.id.tv_cancel).setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick (View view) {
        dismiss();
        switch (view.getId()) {
            case R.id.tv_confirm:
                if (mCallback != null) {
                    mCallback.onConfirm();
                }
                break;
            case R.id.tv_cancel:

                break;
            default:

                break;

        }
    }

    public void showPopupWindow (String msg, Callback callback) {
        super.showPopupWindow();
        mCallback = callback;
        mInfoTv.setText(msg);
    }

    public interface Callback {
        void onConfirm ();
    }
}
